<?php 
session_start();
include("../../conexion.php");
	require_once("../../includes/barramenu.php") ;
	require_once("../../includes/gridView.php")  ;
	require_once("../../includes/combo.php")  	 ;
	$oBarra    = new BarraMenu() 				     ;
	$oBarraSub = new BarraMenu() 				     ;
	$Grid1     = new GridView()					     ;
	$oCombo    = new CmbList()  				     ; 	
?>

<!DOCTYPE html>
<html lang="es">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Ingreso de Comprobantes</title>
<link href="../../includes/css/jquery-ui-notarios.css" rel="stylesheet" type="text/css"/>
<link rel="stylesheet" type="text/css" href="../../tcal.css" />
<link href="../../includes/css/jquery-ui-notarios.css" rel="stylesheet" type="text/css"/>
<link rel="stylesheet" type="text/css" href="../../includes/css/uniform.default.min.css" />
<link rel="stylesheet" type="text/css" href="../../tcal.css" />

<script type="text/javascript" src="../../tcal.js"></script> 
<script type="text/javascript" src="../includes/Mantenimientos.js"></script> 
<script src="../../includes/jquery-1.8.3.js"></script>
<script src="../../includes/js/jquery-ui-notarios.js"></script>
<script src="../../includes/jquery.uniform.min.js"></script>
<script src="../../includes/maskedinput.js"></script>
<script type="text/javascript" src="../../tcal.js"></script> 

<style type="text/css">
div.carta_content {
	background:#333333; 
	border: 1px solid #333333;
	-moz-border-radius: 10px;
	-webkit-border-radius: 10px;
	border-radius: 10px;
	-moz-box-shadow: 0px 0px 7px #000000;
	-webkit-box-shadow: 0px 0px 7px #000000;
	box-shadow: 0px 0px 7px #000000;
	width:638px;
	height:220px;
	position:absolute;
	left: 549px;
	top: 496px;
	margin-top: 15px;
	margin-left: -450px;
	opacity: 0.95;
	filter: "alpha(opacity=50)"; /* expected to work in IE 8 */
	filter: alpha(opacity=50);   /* IE 4-7 */
	zoom: 1;
}

div.allcontrata {width:600px; height:150px; overflow:auto;}
.titupatrimo {font-size: 12; font-style: italic; font-family: Calibri;}

div.div_bloques
{ 
background-color: #ffffff;
border: 4px solid #264965;  
-moz-border-radius: 13px;
-webkit-border-radius: 13px;
border-radius: 13px;
-moz-box-shadow: 0px 0px 5px #000000;
-webkit-box-shadow: 0px 0px 5px #000000;
box-shadow: 0px 0px 5px #000000;
width:820px; height:750px;
}

.camposss {font-family: Calibri; font-style: italic; font-size: 14px; color: #333333; }

.camposss2 {font-family: Calibri; font-style: italic; font-size: 14px; color: #333333; vertical-align:top; text-align:right }


#field_remitente, #field_destinatario, #field_responpago, #field_diligencia, #field_cargo, #div_detfact{
	margin:0 auto;
	border: 2px solid #ddd; 
	border-radius: 10px; 
	padding: 2px; 
	box-shadow: #ccc 5px 0 5px;
	margin-bottom:0px;
	}

.fielSetTipoVista{
	width:100%;
	font-family:Arial, Helvetica, sans-serif;
	font-size:12px;
	color:#000;
	font-weight:bold;
	border:#000 solid 1px;
	box-shadow: #ccc 5px 0 10px;
	border-radius: 10px; 
	}
.detraccion{
	width:100%;
	font-family:Arial, Helvetica, sans-serif;
	font-size:15px;
	text-decoration:blink;
	text-transform:uppercase;
	color:#F00;
	font-weight:bold;
	border-radius: 10px;
	}
	
.detraccion2{
	width:100%;
	font-family:Arial, Helvetica, sans-serif;
	font-size:12px;
	text-transform:uppercase;
	color:#F00;
	font-weight:bold;
	border-radius: 10px;
	}			
.detraccion21 {	width:100%;
	font-family:Arial, Helvetica, sans-serif;
	font-size:12px;
	text-transform:uppercase;
	color:#F00;
	font-weight:bold;
	border-radius: 10px;
}
</style>
<script type="text/javascript">

$(document).ready(function(){ 
	ShowDetComprobante();
	
	document.getElementById('txtNumRows').value = 0 ; 
		
	
	$('#fAgregarItem').attr('style','display:none');
	$('#muesdetracc').attr('style','display:none');
	$('#aplica_detrac').attr('style','display:none');
	
	$('#evalnumero_a').attr('style','display:none');
	$('#evalnumero_b').attr('style','display:none');
	
	$('#div_detfact').attr('style','display:none');
	
	$('#servtipo').val('2');
	

	 //$("input, textarea, select, button").uniform();
	 $("input, textarea").uniform();
	 $("button").button();
	 $("#dialog").dialog();
	 //$("#div_bloques").sortable();
	 $(".ui-dialog-titlebar").hide();
	 //muestragrid();
	})

jQuery(function($){
    $("#fecingreso").mask("99/99/9999",{placeholder:"_"});
	$("#fecentrega").mask("99/99/9999",{placeholder:"_"});
	$("#horaentrega").mask("99:99 aa",{placeholder:"_"});
	$("#fecrecogio").mask("99/99/9999",{placeholder:"_"});
	
	$("#fechade").mask("99/99/9999",{placeholder:"_"});
	$("#fechaa").mask("99/99/9999",{placeholder:"_"});
	
});


////////
function NumCheck(e, field) {
key = e.keyCode ? e.keyCode : e.which
// backspace

if (key == 8) return true
if(key==13){
//document.getElementById("bpag").focus();
}
// 0-9
if (key > 47 && key < 58) {
if (field.value == "") return true
regexp = /.[0-9]{*}$/
return !(regexp.test(field.value))
}
// .
if (key == 46) {
if (field.value == "") return false
regexp = /^[0-9]+$/
return regexp.test(field.value)
}
// other key
return false
}
////////

function crearbloque()
{

var divobs = $('<div id="div_bloques" title="div_bloques"></div>');
// carga con ajax y abre el dialog.
$('<div id="div_bloques" title="div_bloques"></div>').load('CrearBloque.php')
.dialog({
				autoOpen: true,
				position :["center","top"],
                width   : 400,
                height  : 200,
                modal:true,
                resizable:false,
				//show: 'clip',
				//hide: 'clip',
				buttons: [{id: "btnaceptar", text: "Aceptar",click: function() {fcrearBloque();$(this).dialog("close");$("#div_bloques").remove(); }},
				{text: "Cancelar",click: function() { $(this).dialog("close");$("#div_bloques").remove(); }}],
                title:'Crear Bloque'
                }).width(400).height(200);	
				$(".ui-dialog-titlebar").hide();

		
}

function fGraba()
{
	var _numdoc		= document.getElementById('numdoc');
	var _remitente  = document.getElementById('remitente'); 
	var _fec_ingreso    = document.getElementById('fecingreso');
	var _nom_destinatario = document.getElementById('destinatario');
	
	if(_numdoc.value=='' || _remitente.value=='' || _fec_ingreso.value=='' || _nom_destinatario.value=='')
	{alert('Faltan ingresar datos');return;}
	
 fguardaCarta();
}

// #==============================================================
function fGraba2()
{
	// Para evaluar el grabado :
	/*var _id_regventas = document.getElementById('id_regventas').value;
	if(_id_regventas!=''){alert('Factura ya grabada, no se puede modificar');return;}*/
	//
	var _numdoc	  = document.getElementById('numdocumen');
	var _cliente  = document.getElementById('nombre_cliente'); 
	var _fecha    = document.getElementById('fecemision');

	if(_numdoc.value=='' || _cliente.value=='' || _fecha.value=='')
	{alert('Faltan ingresar datos');return;}
	
	else 
	{
		$( "#muesguarda" ).dialog({
			resizable: false,
			height:140,
			position :["center","top"],
			modal: true,
			buttons: {
				"Aceptar": function() { fevalguarda();
				},
				"Cancelar": function() {
					$( this ).dialog( "close" );
				}
			}
		});
	}	
}
// #==============================================================
function fevalguarda()
{
	fguardaComprobante();
	$("#muesguarda").dialog("close");
    //$("#muesguarda").remove();
}



    function fShowDatosProvee(evento) //
		{			
			var _numdoc		= document.getElementById('numdoc').value;
			
			var _remitente  = document.getElementById('nombre_cliente');
			var _direccion  = document.getElementById('direccion_remi');
			var _telefono   = document.getElementById('telefono');
			
			if(evento.keyCode==13) 
				{
					
					if(_numdoc==''){alert('Ingrese un numero de documento');
					$('#nombre_cliente').val('');
					$('#direccion_remi').val('');
					$('#telefono').val('');
					return;}
					
					if(_numdoc.length<=8)
					{
						var _des = fShowAjaxDato('../includes/remitente.php?numdoc='+_numdoc);
						document.getElementById('nombre_cliente').value = _des.replace("*","&").replace("?","'");
						
						var _direcc = fShowAjaxDato('../includes/direccion.php?numdoc='+_numdoc);
						document.getElementById('direccion_remi').value=_direcc.replace("*","&").replace("?","'");
						
						var _telf = fShowAjaxDato('../includes/telefono.php?numdoc='+_numdoc);
						document.getElementById('telefono').value=_telf;
					}
					else if(_numdoc.length>8)
					{
						var _des = fShowAjaxDato('../includes/remitente_ruc.php?numdoc='+_numdoc);
						document.getElementById('nombre_cliente').value = _des.replace("*","&").replace("?","'");
						
						var _direcc = fShowAjaxDato('../includes/domfiscal.php?numdoc='+_numdoc);
						document.getElementById('direccion_remi').value=_direcc.replace("*","&").replace("?","'");
						
						var _telf = fShowAjaxDato('../includes/telefono.php?numdoc='+_numdoc);
						document.getElementById('telefono').value=_telf;
					}
					
					if(_remitente.value==''){alert('No se encuentra registrado');
					$('#numdoc').val('');
					$('#nombre_cliente').val('');
					$('#direccion_remi').val('');
					$('#telefono').val('');
					return;}
				}
		}
		
    function fShowDatosProveeClick() //
		{			
			var _numdoc		= document.getElementById('numdoc').value;
			var _remitente  = document.getElementById('remitente');
			var _direccion  = document.getElementById('direccion_remi');
			var _telefono   = document.getElementById('telefono');

					
					if(_numdoc==''){alert('Ingrese un numero de documento');return;}
					
					var _des = fShowAjaxDato('../includes/remitente.php?numdoc='+_numdoc);
					document.getElementById('remitente').value = _des;
					
					var _direcc = fShowAjaxDato('../includes/direccion.php?numdoc='+_numdoc);
					document.getElementById('direccion_remi').value=_direcc;
					
					var _telf = fShowAjaxDato('../includes/telefono.php?numdoc='+_numdoc);
					document.getElementById('telefono').value=_telf;
					
					if(_remitente==''){alert('No se encuentra registrado');return;}
		}		

function selectzona(_obj)
{
	var _idzona = _obj.substring(4);
	document.getElementById('idzona').value = _idzona;
}

function fCreabloque()
{
	crearbloque();	
}

function fbuscliente()
{
	
}


// PARA ABRIR GRID DE AYUDA:
function fmuescontenido()
{

var divobs = $('<div id="div_ayudacarta" title="div_ayudacarta"></div>');
// carga con ajax y abre el dialog.
$('<div id="div_ayudacarta" title="div_ayudacarta"></div>').load('CartasAyuda.php')
.dialog({
				autoOpen: true,
				position :["center","top"],
                width   : 550,
                height  : 250,
                modal:true,
                resizable:false,
				//show: 'clip',
				//hide: 'clip',
				buttons: [{id: "btnaceptar", text: "Aceptar",click: function() {pasadatos();$(this).dialog("close");$("#div_ayudacarta").remove(); }},
				{text: "Cancelar",click: function() { $(this).dialog("close");$("#div_ayudacarta").remove(); }}],
                title:'Ayuda Cartas'
				
                }).width(550).height(250);	
				$(".ui-dialog-titlebar").hide();


		
}

// #==========================================================================
// #==========================================================================
function newParticipante()
{
	//var _id_viaje = document.getElementById('id_viaje').value;
	//var _id_contratante = "";
	
var divobs = $('<div id="div_newpartic"></div>');
// carga con ajax y abre el dialog.
$('<div id="div_newpartic"></div>').load('NewCliente.php')
.dialog({
				autoOpen: true,
				position :["center","top"],
                width   : 720,
                height  : 350,
                modal:false,
                resizable:false,
				//show: 'clip',
				//hide: 'clip',
				buttons: [{id: "btnAcepPartic2", text: "Aceptar",click: function() {evalGuardaParticipante(); $(this).dialog("destroy").remove(); }},
				{text: "Cancelar",click: function() {$(this).dialog("destroy").remove(); }}],
                title:'Agregar Cliente'
				
                }).width(720).height(350);	
				$(".ui-dialog-titlebar").hide();		
}

// #==========================================================================
// #==========================================================================

function fAddDetalle()
{
	var _id_regventas = document.getElementById('id_regventas').value;
	var _numdoc       = document.getElementById('numdoc').value;
	var _servicio     = document.getElementById('servicio').value;
	var _servprecio   = document.getElementById('servprecio').value;
	var _servcant     = document.getElementById('servcant').value;
	var _servtipo     = document.getElementById('servtipo').value;
	
	/*if(_id_regventas == '')
	{
		alert('Debe ingresar y grabar los datos primero...');return;
	}*/
/*else*/ if(_id_regventas != '')	
	{
		if(_servicio == '' || _servprecio=='' || _servcant=='' || _servtipo=='')
		{alert('Falta ingresar datos del servicio');return;}
		fPassDataItem();			
		
		$('#div_detfact').fadeOut();
	}
	
fCalculosGeneral();	
}

function fCalculosGeneral()
{
	// Math.round(_igv * Math.pow(10, 2)) / Math.pow(10, 2);
	var _tipdocumen   = document.getElementById('tipdocu').value; 
	
	var _servprecio   = parseFloat(document.getElementById('servprecio').value);
	var _servcant     = parseFloat(document.getElementById('servcant').value);
	
	var _subtotal	  = parseFloat(document.getElementById('subtotal').value);
	var _montoigv	  = parseFloat(document.getElementById('montoigv').value);
	var _total		  = parseFloat(document.getElementById('total').value);
	var _detrac       = parseFloat(document.getElementById('detraccion').value);

	var _igv_val      = 0.00;
	var _detraccpor   = 0.12;
	var _detraccion   = 0.00;
	
	if(_tipdocumen=='04' || _tipdocumen=='01')
	{
		_igv_val = 0.00;	
	}
	else 
	{
		_igv_val = 0.18;
	}
	
	/*
	var _sub 		  = (_servprecio * _servcant); // _servprecio * _servcant
	var _igv		  = _igv_val * (_servprecio * _servcant); //(0.82 * _servprecio)
	var _tot   		  = _sub + _igv ;
	*/
	var _igv		  = _igv_val * (_servprecio * _servcant); //(0.82 * _servprecio)
	var _sub 		  = (_servprecio * _servcant) - _igv; // _servprecio * _servcant
	var _tot   		  = _sub + _igv ;

	document.getElementById('subtotal').value   = parseFloat((_subtotal).toFixed(2)) + parseFloat((_sub).toFixed(2)) ;
	
	// Evalua la detraccion del servicio /////
	if(document.getElementById('subtotal').value >= 700)
	{
		_detraccion = parseFloat(document.getElementById('subtotal').value) * _detraccpor ;
		document.getElementById('detraccion').value =  _detraccion;
		$('#muesdetracc').removeAttr('style');
		$('#aplica_detrac').removeAttr('style');
	}
	else if(document.getElementById('subtotal').value < 700)
	{
		_detraccion = 0.00;	
		document.getElementById('detraccion').value =  parseFloat((_detraccion).toFixed(2));
	}
	//////////////////////////////////////////
	var _convert = _montoigv +_igv ;
	//alert(_convert);
	//alert(parseFloat((_convert).toFixed(2)));
	document.getElementById('montoigv').value   = parseFloat((_convert).toFixed(2));
	document.getElementById('total').value      = parseFloat((_total).toFixed(2))  + parseFloat((_tot).toFixed(2)) ;  
		
}

// #=============================================================

function fAddItem()
{	
	var _tdocu = $('#tipdocu').val();
	if(_tdocu=="")
	{alert('Debe seleccionar el tipo de documento');return;}	

	$('#agregarAdd').removeAttr('disabled');
	
	//$('#div_detfact').attr('style','display:none');
	$('#div_detfact').fadeOut();
	
	$('#detalle_fac').val('');
	
	document.getElementById('servicio').value    = ""   ;
	document.getElementById('servprecio').value  = 0.00 ;
	document.getElementById('servcant').value    = 0    ;
	document.getElementById('servtipo').value    = "2"   ;
	//document.getElementById('grupoemp').value    = ""   ;
	
	$('#fAgregarItem').fadeIn();	
}

function fOcultaAdd()
{
	//$('#div_detfact').attr('style','display:none');
	$('#div_detfact').fadeOut();
	$('#detalle_fac').val('');
	
	document.getElementById('servicio').value    = ""   ;
	document.getElementById('servprecio').value  = 0.00 ;
	document.getElementById('servcant').value    = 0    ;
	document.getElementById('servtipo').value    = "2"   ;
	document.getElementById('grupoemp').value    = ""   ;
	
	$('#fAgregarItem').fadeOut();
}

function fAgregaAdd()
{
	fAddDetalle();
	$('#agregarAdd').attr('disabled','disabled');
}

function ShowDetComprobante()
{
//$('#div_detalle').load('listDetComprobante.php');		
}

function fPassData2()
{
	var _id_regventas = document.getElementById('id_regventas').value;
	//$('#div_detalle').load('listDetComprobante.php?id_regventas='+_id_regventas);	
	fCalculosGeneral();
}

function EvalDetrac()
{
	var _servprecio   = parseFloat(document.getElementById('servprecio').value);
	var _servcant     = parseFloat(document.getElementById('servcant').value);
	
	var _subtotal	  = parseFloat(document.getElementById('subtotal').value);
	var _montoigv	  = parseFloat(document.getElementById('montoigv').value);
	var _total		  = parseFloat(document.getElementById('total').value);
	var _detrac       = parseFloat(document.getElementById('detraccion').value);
	
	var _detraccpor   = 0.12;
	var _detraccion   = 0.00;
	
	_detraccion = parseFloat(document.getElementById('subtotal').value) * _detraccpor ;
	  

	var _swtcaja = document.getElementById('aplicadet').checked;

		if (_swtcaja == true)
			{  
			   document.getElementById('total').value      = _total.toFixed(2) + parseFloat((_detraccion).toFixed(2)) ;
			} 
	    else{
			  document.getElementById('total').value      = _total.toFixed(2) - parseFloat((_detraccion).toFixed(2)) ;
			}		
		
}

//tiparea
function fCambiosArea()
		{
			var _cdgarea = $('#tiparea').val();		
			if(_cdgarea=='03' || _cdgarea=='05')
			{		
				$('#evalnumero_b').removeAttr('style');
				$('#evalnumero_a').attr('style','display:none');
				$('#numero').val('');
				$('#num_desde').val('');
				$('#num_hasta').val('');
			}
			else
			{
				$('#evalnumero_a').removeAttr('style');
				$('#evalnumero_b').attr('style','display:none');
				$('#numero').val('');
				$('#num_desde').val('');
				$('#num_hasta').val('');	
			}
		}

function fSelectDetalle()
	{
		var _cdgtipo  = $('#servtipo').val();
		var _textServ = document.getElementById('servicio').options[document.getElementById('servicio').selectedIndex].text; 
		
		if(_cdgtipo=='1')
			{		
				//$('#div_detfact').removeAttr('style');
				$('#div_detfact').fadeIn();
				$('#detalle_fac').val(_textServ);
			}
			else
			{
				//$('#div_detfact').attr('style','display:none');
				$('#div_detfact').fadeOut();
				$('#detalle_fac').val('');
			}
		
	}

function selectMonto()
	{
		var _cdgSrv = $('#servicio').val();
		
		var _monto = fShowAjaxDato('../includes/montoServ.php?cdgsrv='+_cdgSrv);
		document.getElementById('servprecio').value = _monto;	
	}
	
function selectFactIni()
	{	
		// ESCOGE EL CORRELATIVO DEL DOCUMENTO SELECCIONADO DE LA BD
		var _tipdocu = $('#tipdocu').val();
		
		var _documen = fShowAjaxDato('../includes/DocumenIni.php?tipdocu='+_tipdocu);
		var _serie   = fShowAjaxDato('../includes/SerieIni.php?tipdocu='+_tipdocu);
		
		document.getElementById('numdocumen').value = _documen;
		document.getElementById('seriedoc').value   = _serie;
		
		// SELECCIONA LOS VALORES DEL LOS COMBOS; PAGO Y AREA
		if(_tipdocu == '01' || _tipdocu == '02')
		{
			document.getElementById('tippago').value = '1';
			document.getElementById('tiparea').value = '06'; 
			fCambiosArea();
			
		}else
			{
				document.getElementById('tippago').value = "";
				document.getElementById('tiparea').value = ""; 
				fCambiosArea();
				
				$('#evalnumero_a').attr('style','display:none');
				$('#evalnumero_b').attr('style','display:none');
				$('#numero').val('');
				$('#num_desde').val('');
				$('#num_hasta').val('');					
			}		

		
		// SELECCIONA EL GRUPO DE SERVICIOS SEGUN EL TIPO DE DOCUMENTO
		selectServiTipo();
		
		// SI ES BOLETA O RECIBO OCULTA EL CAMPO IGV
		if(_tipdocu == '01' || _tipdocu == '04')
		{
			$('.div_subtotal').attr('style','display:none');
		}else
			{
				$('.div_subtotal').removeAttr('style','display:none');
			}
		
	}	

function ChangeFocus3()
{document.getElementById('Nuevo').focus();}


function ChangeFocus2()
{document.getElementById('seriedoc').select();}
	
// servicio
function ChangeFocus()
{document.getElementById('servprecio').select();}

function focus1(evento)
  {if(evento.keyCode==13){document.getElementById('servcant').select();}} 


function focus2(evento)
  {if(evento.keyCode==13){document.getElementById('agregarAdd').focus();}} 
  
function focus3(evento)
  {if(evento.keyCode==13){document.getElementById('numdocumen').focus();}} 

function focus4(evento)
  {if(evento.keyCode==13){document.getElementById('numdoc').focus();}} 


function fimpresion()
{
	var _id_regventas = document.getElementById('id_regventas').value;
	if(_id_regventas==''){alert('Debe guardar los datos primero');return;}

    var _usuario_imprime = '<?php echo $_SESSION["apepat_usu"].' '.$_SESSION["nom1_usu"]; ?>';

	document.getElementById('Grabar').disabled = true;
window.open('../Reportes/impresion_factura.php?id_regventas='+_id_regventas,"Impresion de Factura","status=1,scrollbars=1, menubar=0,resizable=0,width=350,height=250");	
	
}


function abre_div_metodo1()
	{
		$('#btn_1').unbind();
		var _div_a = $('#div_a');
		
		_div_a.dialog({
				autoOpen: true,
				position :["center","top"],
                width   : 720,
                height  : 350,
                modal:false,
                resizable:false,
				//show: 'clip',
				//hide: 'clip',
				buttons: [{id: "btn1", text: "Aceptar",click: function() {$(this).dialog("close"); }},
				{text: "Cancelar",click: function() {$(this).dialog("close"); }}],
                title:'titulo 1'
				
                }).width(720).height(350);	
				//$(".ui-dialog-titlebar").hide();			
			
	}	

function abre_div_metodo2()
	{
		$('#btn_2').unbind();
		$('<div id="div1" title="div1"></div>').load('ComprobantesVie.php').dialog({
				autoOpen: true,
				position :["center","top"],
                width   : 720,
                height  : 350,
                modal:false,
                resizable:false,
				//show: 'clip',
				//hide: 'clip',
				buttons: [{id: "btn2", text: "Aceptar",click: function() {$(this).dialog("close"); }},
				{text: "Cancelar",click: function() {$(this).dialog("close"); }}],
                title:'titulo 2'
				
                }).width(720).height(350);	
				//$(".ui-dialog-titlebar").hide();		
			
	}	
	
	
function selectServiTipo()
	{	
		var _tipdocu = $('#tipdocu').val();
		
		var _cmbServ = fShowAjaxDato('../includes/comboServ.php?tipdocu='+_tipdocu);
		
		document.getElementById('combo_servicios').innerHTML = _cmbServ;
	}

// FUNCION PARA AGREGAR FILAS A LA TABLA:
function fAgrRow(obj,numCol)
		{
			//var _div = document.getElementById('div_detalle').firstChild.nodeValue = 
			//Agrega Filas a una tabla 
			var _tbody = document.getElementById('Table_det_Serv').getElementsByTagName("TBODY")[0];
			var _row   = document.createElement("TR")
			var _fil   = document.getElementById('Table_det_Serv').rows.length;
			_row.setAttribute('id','f'+_fil);
			_row.setAttribute('name','f'+_fil);
			
			for(i=1;i<=numCol;i++)
				{
				 var _td = document.createElement("TD");
				 _td.appendChild(document.createTextNode(""));
				 _row.appendChild(_td); 
				}
				
			var _tdDatos = document.createElement("TD");
			_tdDatos.setAttribute('style','display:none');
			
			var _datos   = document.createElement("input");
			_datos.setAttribute('type','hidden');
			_datos.setAttribute('value','');
			_datos.setAttribute('id','datos'+_fil);
			_datos.setAttribute('name','datos'+_fil);

			_tdDatos.appendChild(_datos);
			_row.appendChild(_tdDatos);
			_tbody.appendChild(_row);
		}

// FUNCION PARA PASAR LOS VALORES SELECCIONADOS
function passValores()
{
		var _tipdocu     = document.getElementById('tipdocu').value; // Evalucion Montos IGV 
		var _detalle_fac = document.getElementById('detalle_fac').value;
		
		fAgrRow(document.getElementById('Table_det_Serv'),5)
		
		var _fil        = document.getElementById('Table_det_Serv').rows.length-1;
		
		var _codigo     = document.getElementById('servicio').value;
		if(_detalle_fac=='')
		{var _servicio	= document.getElementById('servicio').options[document.getElementById('servicio').selectedIndex].text ;}
		else if(_detalle_fac!='')
		{var _servicio	= document.getElementById('detalle_fac').value;}
		
		// Evaluación de IGV - Según Tipo de Documento:
		var _valigv = 1;
		if(_tipdocu=='02' || _tipdocu=='03')
		{
			var _valigv = 0.82;	
		}
		
		var _precio     = parseFloat(document.getElementById('servprecio').value);
		var _cantidad   = parseFloat(document.getElementById('servcant').value);
		var _total      = _precio * _cantidad * _valigv ;
		
		
		
		document.getElementById('f'+_fil).cells[0].innerHTML = _codigo;
		document.getElementById('f'+_fil).cells[1].innerHTML = _servicio.toUpperCase();
		document.getElementById('f'+_fil).cells[2].innerHTML = (_valigv * _precio).toFixed(2);
		document.getElementById('f'+_fil).cells[3].innerHTML = _cantidad;
		document.getElementById('f'+_fil).cells[4].innerHTML = parseFloat((_total).toFixed(2));
		document.getElementById('f'+_fil).cells[5].innerHTML = _codigo+'|'+_servicio+'|'+_precio+'|'+_cantidad+'|'+_total;
		
		document.getElementById('txtTotServicios').value = document.getElementById('txtTotServicios').value+'┘'+_codigo+'|'+_servicio+'|'+_precio+'|'+_cantidad+'|'+_total;
		document.getElementById('txtNumRows').value = _fil;	
}

//Poner ceros a la izquierda:
function ponerCeros(obj) {
  var _tiparea = document.getElementById('tiparea').value;
  if(_tiparea=="01")
  {	
  	while (obj.value.length<6)
    	obj.value = '0'+obj.value;  
  }	
}

function ListComprobantes()
{
		$('#ListaComp').unbind();
		$('<div id="divListComp" ></div>').load('ListCompEmi.php').dialog({
				autoOpen: true,
				position :["center","top"],
                width   : 880,
                height  : 350,
                modal:false,
                resizable:false,
				//show: 'clip',
				//hide: 'clip',
				buttons: [{id: "btnAcept_Com", text: "Aceptar",click: function() {$(this).dialog("destroy").remove(); }},
				{text: "Cancelar",click: function() {$(this).dialog("destroy").remove(); }}],
                title:'Lista de Comprobantes'
				
                }).width(880).height(350);	
				$(".ui-dialog-titlebar").hide();		
		
}
	
</script>
</head>

<body style="font-size:62.5%;">
<div id="div_a" title="div_a" style="display:none">CONTENIDO DEL DIV BASICO EN LA PAGINA PRINCIPAL</div>
<div id="carta_content">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
	<td width="1%">
     <?php
				//$oBarra->Nuevo        = "1"             ;
				//$oBarra->NuevoClick   = "agregar();"    ;
				$oBarra->Graba        = "1"               ;
				$oBarra->GrabaClick   = "fGraba2();"      ;
				$oBarra->Impri        = "1"               ;
				$oBarra->ImpriClick   = "fimpresion();"   ;
				//$oBarra->refresh      = "1"          	  ;
				//$oBarra->refreshClick = "frefresh();"   ;
				//$oBarra->Elimi        = "1"             ;
				//$oBarra->ElimiClick   = "fElimina();"   ;
				//$oBarra->Busca      = "1"           	  ;
				//$oBarra->itemBusca  = "Descripcion"	  ; 
				//$oBarra->BuscaClick = "fBuscaTKardex()" ;
			    //$oBarra->onKeytxt   = "focusSearch(event)";
				$oBarra->clase        = "css"      		    ; 
				$oBarra->widthtxt     = "20"				; 
				$oBarra->Show()  						    ; 
	  ?>
    </td><td width="0%" align="right"><div id="resul_documen" style="width:100%;"></div></td>
    <td width="12%" align="left"><span style="width:100%;">
      <button title="Listar" type="button" name="ListaComp"    id="ListaComp" value="Listar" onclick="ListComprobantes();" ><img  src="../../images/block.png" alt="" width="15" height="15" align="absmiddle" />Comprobantes</button>
    </span></td>
    <td width="87%" align="left"><span style="width:100%;">
      <input name="id_regventas" type="hidden" id="id_regventas" />
      <input name="id_numbouc" id="id_numbouc" type="hidden">
    </span></td>
</tr>
</table>
<table width="100%" border="0" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF">
  <tr>
    <td><table  width="100%">
      <tr>
        <td colspan="8"><div id="muesguarda" title="Confirmacion" style="display:none"><center>Desea guardar el Documento..?</center><br><center>Verifique los datos antes de guardar.</center></div><div id="confirmaGuarda"></div></td>
        </tr>
      <tr>
        <td width="14%"><span class="camposss">
        
         <!--<input type="button" name="btn_1" id="btn_1" value="DIV_BASICO" onClick="abre_div_metodo1();">
          <input type="button" name="btn_2" id="btn_2" value="DIV_AJAX" onClick="abre_div_metodo2();"> -->
          
          Tipo de Documento:</span></td>
        <td width="16%"><?php 
			$oCombo = new CmbList()  ;					 		
			$oCombo->dataSource = "SELECT tip_documen.id_documen AS 'id', tip_documen.des_docum AS 'des' FROM tip_documen ORDER BY tip_documen.des_docum ASC"; 
			$oCombo->value      = "id";
			$oCombo->text       = "des";
			$oCombo->size       = "120"; 
			$oCombo->name       = "tipdocu";
			$oCombo->style      = "camposss"; 
			$oCombo->click      = "selectFactIni();ChangeFocus2();";   
			$oCombo->selected   =  $variable;
			$oCombo->Show();
			$oCombo->oDesCon(); 
?></td>
        <td width="17%" align="right"><span class="camposss">N. Docum.:</span></td>
        <td width="33%">
        <div id="resul_documen2" style="width:100%;"><input name="seriedoc" type="text" id="seriedoc" style="text-transform:uppercase" size="1" onkeypress="focus3(event);" />-
          <input name="numdocumen" type="text" id="numdocumen" style="text-transform:uppercase" size="10" onkeypress="focus4(event);" /></div></td>
        <td width="17%" align="right"><span class="camposss">Fecha Emision:</span> </td>
        <td width="18%"><input name="fecemision" type="text" id="fecemision" style="text-transform:uppercase" value="<?php echo date("d/m/Y"); ?>" size="9" class="tcal" /></td>
        <td width="18%" align="right"><span class="camposss">Empleado:</span></td>
        <td width="36%"><input name="usuario_sesion" type="text" id="usuario_sesion" style="text-transform:uppercase" size="15" value="<?php echo $_SESSION["apepat_usu"].' '.$_SESSION["nom1_usu"]; ?>" /></td>
        </tr>
    </table></td>
  </tr>
  <tr>
    <td>
    <fieldset id="field_remitente">
    <legend></legend>
    <table  width="100%">
        <tr>
          <td width="14%"><span class="camposss">N.documento :</span></td>
          <td width="37%"><input name="numdoc" type="text" id="numdoc" style="text-transform:uppercase" onkeypress="fShowDatosProvee(event);" size="15" />
            <input name="idcliente" type="hidden" id="idcliente" />
            <a href="#" onClick="newParticipante();//fShowDatosProveeClick()"> <img src="../../images/search.png" width="15" height="15" alt="" /></a></td>
          <td width="19%"><span class="camposss">Telefono:</span></td>
          <td width="30%"><input name="telefono" type="text" id="telefono" style="text-transform:uppercase" size="15" /></td>
        </tr>
        <tr>
          <td><span class="camposss">Nombre Cliente:</span> </td>
          <td colspan="3"><input name="nombre_cliente" type="text" id="nombre_cliente" style="text-transform:uppercase" size="60" /></td>
          </tr>
        <tr>
          <td><span class="camposss">Direccion:</span> </td>
          <td colspan="3"><input name="direccion_remi" style="text-transform:uppercase" type="text" id="direccion_remi" size="60" /></td>
        </tr>
        </table>
    </fieldset>  
      </td>
    </tr>
  <tr>
    <td>&nbsp;</td>
    </tr>
  <tr>
    <td>
    <!--<fieldset id="field_responpago">
    <legend><span class="camposss">Responsable de ingreso</span></legend>
    <table  width="100%">
        <tr>
          <td width="14%"><span class="camposss">Encargado:</span></td>
          <td colspan="3"><input name="idencargado" type="text" id="idencargado" style="text-transform:uppercase" size="15" /></td>
          </tr>
        </table>
    </fieldset>-->
    </td>
    </tr>
  <tr>
    <td >
    <fieldset id="field_diligencia">
    <legend><span class="camposss">Detalle 1</span></legend>
    <table  width="100%">
        <tr>
          <td width="4%" align="right"><span class="camposss">Pago:</span></td>
          <td width="8%"><?php 
			$oCombo = new CmbList()  ;					 		
			$oCombo->dataSource = "SELECT tipo_pago.codigo AS 'id', tipo_pago.descrip AS 'des' FROM tipo_pago ORDER BY tipo_pago.descrip ASC"; 
			$oCombo->value      = "id";
			$oCombo->text       = "des";
			$oCombo->size       = "150"; 
			$oCombo->name       = "tippago";
			$oCombo->style      = "camposss"; 
			$oCombo->click      = "//selectzona(this.value);";   
			$oCombo->selected   =  $variable;
			$oCombo->Show();
			$oCombo->oDesCon(); 
?></td>
          <td width="7%" align="right"><span class="camposss">Area:</span> </td>
          <td width="13%"><?php 
			$oCombo = new CmbList()  ;					 		
			$oCombo->dataSource = "SELECT area_detalle.id_area AS 'id', area_detalle.des_area AS 'des' FROM area_detalle ORDER BY area_detalle.des_area ASC"; 
			$oCombo->value      = "id"; 
			$oCombo->text       = "des";
			$oCombo->size       = "150"; 
			$oCombo->name       = "tiparea"; 
			$oCombo->style      = "camposss"; 
			$oCombo->click      = "fCambiosArea();";   
			$oCombo->selected   =  $variable;
			$oCombo->Show();
			$oCombo->oDesCon(); 
?></td> 
          <td width="38%">
          <div id="evalnumero_a">
          <span class="camposss">Numero:</span><!--<input name="empentrega" type="text" id="empentrega" style="text-transform:uppercase" size="30" />-->
            <input name="numero" type="text" id="numero" style="text-transform:uppercase" size="15" onBlur="ponerCeros(this);" />
           </div>  
           <div id="evalnumero_b">
           <span class="camposss">Del:</span>
           <input name="num_desde" type="text" id="num_desde" style="text-transform:uppercase" size="2" />
           <span class="camposss">Al:</span>
           <input name="num_hasta" type="text" id="num_hasta" style="text-transform:uppercase" size="2" />
           </div>  

            </td>
          <td width="15%"> <span class="camposss">Atendido por:</span></td>
          <td width="15%" style="text-transform:uppercase;">
          <?php 
			$oCombo = new CmbList()  ;					 		
			$oCombo->dataSource = "SELECT usuarios.loginusuario AS 'id' ,UPPER(CONCAT(usuarios.apepat,' ',usuarios.apemat, ', ',usuarios.prinom)) AS 'des' FROM usuarios
ORDER BY usuarios.apepat ASC"; 
			$oCombo->value      = "id";
			$oCombo->text       = "des";
			$oCombo->size       = "150"; 
			$oCombo->name       = "grupoemp";
			$oCombo->style      = "camposss"; 
			$oCombo->click      = "//selectzona(this.value);";   
			$oCombo->selected   =  $variable;
			$oCombo->Show();
			$oCombo->oDesCon(); 
?>
          
          </td>
             
          </tr>
        </table>
    </fieldset>
    </td>
    </tr>
  <tr>
    <td ><hr> </td>
  </tr>
  <tr>
    <td >
    <table  width="100%">
        <tr>
          <td>
          <?php
				$oBarraSub->Nuevo        = "1"                 ; 
				$oBarraSub->NuevoClick   = "fAddItem();"       ;
				//$oBarraSub->Graba        = "1"               ;
				//$oBarraSub->GrabaClick   = "fGraba2();"      ;
				//$oBarraSub->Impri        = "1"               ;
				//$oBarraSub->ImpriClick   = "//fGenerar();"   ;
				//$oBarraSub->refresh      = "1"          	   ;
				//$oBarraSub->refreshClick = "frefresh();"     ;
				//$oBarraSub->Elimi      = "1"           	   ;
				//$oBarraSub->ElimiClick = "fElimina();"  	   ;
				//$oBarraSub->Busca      = "1"           	   ;
				//$oBarraSub->itemBusca  = "Descripcion"	   ; 
				//$oBarraSub->BuscaClick = "fBuscaTKardex()"   ;
			    //$oBarraSub->onKeytxt   = "focusSearch(event)";
				$oBarraSub->clase        = "css"      		   ; 
				$oBarraSub->widthtxt   = "20"				   ; 
				$oBarraSub->Show()  						   ; 
				?>
          </td>
          <td>
          <div id="muesdetracc"><span class="detraccion">DOCUMENTO SUJETO A DETRACCIÓN</span></div>
          </td>
          </tr>
          <tr>
          <td colspan="2">
            <div id="fAgregarItem" class="fielSetTipoVista">
				<table border="0" width="100%">
    				<tr>
        				<td width="18%" align="right">Servicio:</td>
        				<td width="23%"><div id="combo_servicios"></div></td>
        				<td width="32%" align="right">Tipo:</td>
                        <td width="27%"><?php 
			$oCombo = new CmbList()  ;					 		
			$oCombo->dataSource = "SELECT tipo_serv.id_serv AS 'id', tipo_serv.des_tipserv AS 'des' FROM tipo_serv ORDER BY tipo_serv.des_tipserv ASC"; 
			$oCombo->value      = "id";
			$oCombo->text       = "des";
			$oCombo->size       = "120"; 
			$oCombo->name       = "servtipo";
			$oCombo->style      = "camposss"; 
			$oCombo->click      = "fSelectDetalle();";   
			$oCombo->selected   =  $variable;
			$oCombo->Show();
			$oCombo->oDesCon(); 
?></td>
        			</tr>
    				<tr>
    				  <td align="right">Precio:</td>
    				  <td><input name="servprecio" type="text" id="servprecio" style="text-transform:uppercase; text-align:right;" value="0.00" size="15" onkeypress="focus1(event); return NumCheck(event, this);" /></td>
    				  <td align="right">&nbsp;</td>
    				  <td></td>
  				  </tr>
    				<tr>
    				  <td align="right">Cantidad:</td>
    				  <td><input name="servcant" type="text" id="servcant" style="text-transform:uppercase; text-align:right;" value="0" size="15" onkeypress="focus2(event); return NumCheck(event, this);" /></td>
    				  <td>&nbsp;</td>
    				  <td>&nbsp;</td>
  				  </tr>
    				<tr>
    				  <td colspan="4" align="right"><hr align="center" width="90%"></td>
   				  </tr>
    				<tr>
    				  <td>&nbsp;</td>
    				  <td align="center">&nbsp;</td>
    				  <td align="center">&nbsp;</td>
    				  <td align="center"><button title="Agregar" type="button" name="agregarAdd"    id="agregarAdd" value="Agregar" onclick="passValores();fAgregaAdd();ChangeFocus3();" ><img src="../../images/success.png" alt="" width="18" height="18" /></button> &nbsp;&nbsp;   				    <button title="Cerrar" type="button" name="cerrarAdd"    id="cerrarAdd" value="Cerrar" onclick="fOcultaAdd();" ><img src="../../images/delete.png" alt="" width="18" height="18" /></button></td>
  				  </tr>
    			</table>
			</div>
          </td>
          </tr>
          <tr>
          <td colspan="2" align="center" valign="top">
          <div id="div_detfact">
          <span class="camposss2" >Detalle:</span>
          <textarea id="detalle_fac" name="detalle_fac" cols="100" rows="3" style="text-transform:uppercase;"></textarea>
          </div>
          </td>
          </tr>
        </table>
    </td>
  </tr>
  <tr>
    <td height="30" valign="top" ><input id="txtNumRows" name="txtNumRows" type="hidden" value="0">
    <input id="txtTotServicios" name="txtTotServicios" type="hidden">
    <br>
    
    
    
    <div id="div_detalle" style='border: 1px solid #264965;border-radius: 5px;width:100%; height:120px; font-size:14px;'>
    <table id="Table_det_Serv" name="Table_det_Serv" width="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#333333" bgcolor="#CCCCCC">
            <tr>
              <td width="150" align="left"><span class="titubuskar0">Codigo</span></td>
              <td width="350" align="left"><span class="titubuskar0">Descripcion</span></td>
              <td width="120" align="right"><span class="titubuskar0">Precio</span></td>
              <td width="120" align="right"><span class="titubuskar0">Cantidad</span></td>
              <td width="120" align="right"><span class="titubuskar0">Total</span></td>
              <td style="display:none"></td>
            </tr>      
          </table>
    
    </div>
    </td>
    </tr>
  <tr>
    <td height="30" align="right" >&nbsp;</td>
  </tr>
  <tr>
    <td height="30" align="center" ><table  width="100%">
        <tr>
          <td width="27%" align="left"><div id="aplica_detrac"><span class="detraccion2"><span class="detraccion21">
            <input id="aplicadet" name="aplicadet" type="checkbox" value="0" onChange="EvalDetrac();">
          </span>AUTODETRACCIÓN</span></div></td>
          <td width="28%" align="right"><span class="camposss"> 
            <input name="swt_det" type="hidden" id="swt_det" />
            <input name="detraccion" type="hidden" id="detraccion" value="0.00" />
            <div class="div_subtotal">Sub Total:</div></span></td>
          <td width="12%"><div class="div_subtotal"><input name="subtotal" type="text" id="subtotal" style="text-transform:uppercase; text-align:right;" value="0.00" size="15" readonly="readonly" onkeypress="return NumCheck(event, this);" /></div></td>
          <td width="6%" align="right"><span class="camposss"><div class="div_subtotal">IGV(18%):</div></span> </td>
          <td width="7%"><div class="div_subtotal"><input name="montoigv" type="text" id="montoigv" style="text-transform:uppercase ;text-align:right;" value="0.00" size="15" readonly="readonly" onkeypress="return NumCheck(event, this);" /></div></td>
          <td width="7%" align="right"><span class="camposss">Total:</span></td>
          <td width="13%"><!--<input name="empentrega" type="text" id="empentrega" style="text-transform:uppercase" size="30" />-->
            <input name="total" type="text" id="total" style="text-transform:uppercase; text-align:right;" value="0.00" size="15" readonly="readonly" onkeypress="return NumCheck(event, this);" /></td>
          </tr>
        </table></td>
  </tr>
</table>
</div>
</body>
</html>
